﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.IO;

namespace AramaruForest
{
    class GameState
    {
        public SizeF GameSize;
        public World _world;
        public Read _read;
        public Menu _menu;
        public bool GameIsWon;
        public bool world;
        public bool read;
        public bool menu;
        public List<string> _messages = new List<string>();
        public int _messageCount = 0;

        public GameState(SizeF gameSize)
        {
            GameSize = gameSize;
            
        }

        public void Update(double gameTime, double elapsedTime)
        {
            if (world && !menu && !read)
            {
                _world.Update(gameTime, elapsedTime);

                
            }
            else if(menu && !world && !read)
            {
            }
            else if(read && !world && !menu)
            {
            }
            else
            {
                throw new Exception("Inconsistancy in game state. (world, menu and read were not contigous)");
            }
        }

        public void Draw(Graphics graphics)
        {
            _world.Draw(graphics);
        }

        public void Initialize()
        {
            _world = new World(this);
            _read = new Read(this);
            _menu = new Menu(this);
            menu = false;
            read = false;
            world = true;
        }

        public void ReadMessages()
        {
            StreamReader l = new StreamReader(@"Data\Messages.txt");
            while (!l.EndOfStream)
            {
                _messages.Add(l.ReadLine());
            }
            
        }

        public void KeyDown(Keys keys)
        {
            if (keys == Keys.P)
            {

                _world._gameItems.Hero.hp = 0;
            }
            //If the game is not over then allow the user to play
            if (_world._gameItems.Hero.Hp > 0)
            {
                if(!_world._gameItems.Hero.Thrown)
                    _world.KeyDown(keys);
            }
            
        }
    }
}
